﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using InstantNaukriDAL;
using System.Collections.Generic;
using System.Globalization;

public partial class JobseekerProfile_EditProjectDetails : System.Web.UI.Page
{
    int ProfileId = 0, UserId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UserId"] == null)
                Response.Redirect("Default.aspx");
            string roleid = "";
            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            if (Request.QueryString["roleid"] != null)
                roleid = clsEncryptionDecryption.Decrypt(Request.QueryString["roleid"].ToString());
            if (roleid == "4")
            {
                IN_TB_USER objIN_TB_USER = new IN_TB_USER();
                if (Session["UserId"] != null)
                    objIN_TB_USER = objclsUserLoginDAL.GetUserByID(Convert.ToInt32(Session["UserId"].ToString()));
                if (objIN_TB_USER != null)
                {
                    Session["UserId"] = objIN_TB_USER.ID;
                    dvAutority.Visible = true;
                    Fillddls();
                    CreateProjectList();
                    FillProjectDetails(objIN_TB_USER.ID);
                }
            }
        }
    }

    protected void FillProjectDetails(int UserId)
    {
        try
        {
            List<IN_TB_USER_PROJECT> objIN_TB_USER_PROJECTList = new List<IN_TB_USER_PROJECT>();
            clsProjectDetailDAL objclsProjectDetailDAL = new clsProjectDetailDAL();
            objIN_TB_USER_PROJECTList = objclsProjectDetailDAL.GetProjectByUserId(UserId);
            if (objIN_TB_USER_PROJECTList != null)
            {
                grdProjectDetails.DataSource = objIN_TB_USER_PROJECTList;
                grdProjectDetails.DataBind();
                Session["objIN_TB_USER_PROJECT"] = objIN_TB_USER_PROJECTList;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    protected void CreateProjectList()
    {
        List<IN_TB_USER_PROJECT> objIN_TB_USER_PROJECT = new List<IN_TB_USER_PROJECT>();
        Session["objIN_TB_USER_PROJECT"] = objIN_TB_USER_PROJECT;
    }
    protected void btnAddProject_Click(object sender, EventArgs e)
    {
        List<IN_TB_USER_PROJECT> objIN_TB_USER_PROJECTList = new List<IN_TB_USER_PROJECT>();
        objIN_TB_USER_PROJECTList = (List<IN_TB_USER_PROJECT>)Session["objIN_TB_USER_PROJECT"];
        IN_TB_USER_PROJECT objIN_TB_USER_PROJECT = new IN_TB_USER_PROJECT();
        objIN_TB_USER_PROJECT.DESIGNATION = txtDesignation.Text;
        objIN_TB_USER_PROJECT.DURATION_END= DateTime.ParseExact(txtEndDate.Text, "dd-MMM-yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None);
        objIN_TB_USER_PROJECT.DURATION_START = DateTime.ParseExact(txtStarrDate.Text, "dd-MMM-yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None);
        objIN_TB_USER_PROJECT.EMPLOYER_NAME = txtEmployer.Text;
        objIN_TB_USER_PROJECT.EMPLOYMENT_TYPE = txtProjectEmploymentType.Text;
        objIN_TB_USER_PROJECT.EXPERIENCE = Convert.ToInt32(ddlProjectExperience.SelectedValue);
        objIN_TB_USER_PROJECT.PROJECT_DETAILS = txtProjectDetails.Text;
        objIN_TB_USER_PROJECT.PROJECT_LOCATION = Convert.ToInt32(ddlProjectLocation.SelectedValue);
        objIN_TB_USER_PROJECT.PROJECT_TITLE = txtProjectTiltel.Text;
        objIN_TB_USER_PROJECT.ROLE = txtRole.Text;
        objIN_TB_USER_PROJECT.ROLE_DESCRIPTION = txtRoleDescription.Text;
        objIN_TB_USER_PROJECT.SKILLS_USED = txtProjectKeySkills.Text;
        objIN_TB_USER_PROJECT.TEAM_SIZE = Convert.ToInt32(txtTeamSize.Text);
        objIN_TB_USER_PROJECTList.Add(objIN_TB_USER_PROJECT);
        //clsProjectDetailDAL objProjectDetailDAL = new clsProjectDetailDAL();
        //objProjectDetailDAL.SaveProject(objIN_TB_USER_PROJECT);
        Session["objIN_TB_USER_PROJECT"] = objIN_TB_USER_PROJECTList;
        grdProjectDetails.DataSource = objIN_TB_USER_PROJECTList;
        grdProjectDetails.DataBind();
    }

    private void Fillddls()
    {
        try
        {
            // Project Location
            clsCity objclsCity = new clsCity();
            List<IN_TB_CITY> objIN_TB_CITY = new List<IN_TB_CITY>();
            objIN_TB_CITY = objclsCity.GetAllCities();
            ddlProjectLocation.Items.Clear();
            ddlProjectLocation.AppendDataBoundItems = true;
            ddlProjectLocation.DataTextField = "CITY";
            ddlProjectLocation.DataValueField = "ID";
            ddlProjectLocation.Items.Add("Select");
            ddlProjectLocation.Items[0].Value = "0";
            ddlProjectLocation.DataSource = objIN_TB_CITY;
            ddlProjectLocation.DataBind();

            // Project Experience
            ddlProjectExperience.Items.Clear();
            ddlProjectExperience.AppendDataBoundItems = true;
            ddlProjectExperience.Items.Add("Select");
            ddlProjectExperience.Items[0].Value = "0";
            for (int i = 1; i <= 60; i++)
            {
                ddlProjectExperience.Items.Add(i.ToString());
                ddlProjectExperience.Items[i].Value = i.ToString();
            }
            ddlProjectExperience.DataBind();
        }
        catch (Exception ex)
        {
        }
    }


    protected void grdProjectDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Getting Preferred Location
            int Preferred_locationId = Convert.ToInt32(e.Row.Cells[4].Text);
            clsCity objclsCity = new clsCity();
            IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
            objIN_TB_CITY = objclsCity.GetCityById(Preferred_locationId);
            e.Row.Cells[4].Text = objIN_TB_CITY.CITY;
        }
    }

    protected void btnProjectDetaiils_Click(object sender, EventArgs e)
    {
        try
        {
            List<IN_TB_USER_PROJECT> objIN_TB_USER_PROJECTList = new List<IN_TB_USER_PROJECT>();
            objIN_TB_USER_PROJECTList = (List<IN_TB_USER_PROJECT>)Session["objIN_TB_USER_PROJECT"];
            clsProjectDetailDAL objclsProjectDetailDAL = new clsProjectDetailDAL();

            foreach (IN_TB_USER_PROJECT objIN_TB_USER_PROJECT in objIN_TB_USER_PROJECTList)
            {
                if (Session["UserId"] != null)
                    objIN_TB_USER_PROJECT.USERID = Convert.ToInt32(Session["UserId"]);
                objIN_TB_USER_PROJECT.CREATED_BY = 1;
                objIN_TB_USER_PROJECT.MODIFIED_BY = 1;
                objclsProjectDetailDAL.SaveProject(objIN_TB_USER_PROJECT);
            }

            if (Request.QueryString["roleid"] != null && Session["UserId"] != null)
            {
                Response.Redirect("JobseekerPrieview.aspx?roleid=" + Request.QueryString["roleid"].ToString());
            }
            else
            {
                Session["RoleId"] = null;
                Response.Redirect("JobSeekerLogin.aspx");
            }
        }
        catch (Exception)
        {

            throw;
        }


    }



}
